Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm] First attempt at a wasm app host #68696

Merged
merged 6 commits into from
May 25, 2022
Merged

Conversation

radical
Copy link
Member

@radical radical commented Apr 29, 2022

First attempt at implementing a wasm app host

Regular dotnet apps can be run with dotnet run. But this is not the case for
wasm apps. We use xharness to run the test apps that we generate for library
tests.

Templates for browser, and console wasm projects were added recently, but they
have to be run manually by either invoking a v8 script, or running a
http-server in the bundle directory. Though to use a debugger with this
requires starting the debug proxy separately, and connecting few bits.

WasmAppHost

This PR adds a new WasmAppHost, which can be used through dotnet run:

  • it can run "wasm app" from it's AppBundle directory, using various hosts
    like v8, node, or a browser. An example use:

    $ dotnet new wasmconsole
    $ dotnet run
    WasmAppHost --runtime-config /tmp/c0/bin/Debug/net7.0/browser-wasm/AppBundle//c0.runtimeconfig.json
    [02:26:40] info: host[0] Running: node main.cjs
    [02:26:40] dbug: host[0] Using working directory: /tmp/c0/bin/Debug/net7.0/browser-wasm/AppBundle
    Incoming arguments:
    Application arguments:
    Debugger.Debug: DEBUGGING ENABLED
    
    mono_wasm_runtime_ready fe00e07a-5519-4dfe-b35a-f867dbaf2e28
    Could not find symbols file dotnet.js.symbols. Ignoring.
    Initializing.....
    Hello, Console!
    

    The console template project is run with node by default.

  • it supports a --debug parameter, which (for the browser case) would startup
    a webserver, and the debug proxy for Chrome, and firefox.

$ dotnet new wasmbrowser

$ dotnet run --debug
WasmAppHost --runtime-config /workspaces/test/br0/bin/Debug/net7.0/browser-wasm/AppBundle//br0.runtimeconfig.json --debug --forward-console
Debug proxy for chrome now listening on http://127.0.0.1:9300/. And expecting chrome at http://localhost:9222/
Hosting environment: Production
Content root path: /workspaces/test/br0/bin/Debug/net7.0/browser-wasm/AppBundle
Now listening on: http://127.0.0.1:9300
Debug proxy for firefox now listening on tcp://127.0.0.1:6300. And expecting firefox at port 6000 .

App url: http://127.0.0.1:9000/index.html
App url: https://127.0.0.1:38331/index.html
  • This enables using dotnet run with wasm samples, and library tests too.

How do I try this out?

You'll need a dotnet with the updated packs. For now, you can use:

$ ./dotnet.sh build -p:TargetOS=Browser -p:TargetArchitecture=wasm -p:Configuration=Release src/tests/BuildWasmApps/Wasm.Build.Tests/Wasm.Build.Tests.csproj /t:InstallWorkloadUsingArtifacts

.. which would install a sdk in artifacts/bin/dotnet-workload with all the packs installed.

  • Use that dotnet to create console, or browser wasm apps from templates, for example dotnet new wasmconsole, or dotnet new wasmbrowser.

Debugging library tests

runtime$ ./artifacts/bin/dotnet-workload/dotnet run -f net7.0 -r browser-wasm -c $YourRuntimeConfig --project src/libraries/System.Buffers/tests/System.Buffers.Tests.csproj -p:DebuggerSupport=true --debug --host browser
  • If the runtime was built in Release config, then you need to add -p:DebuggerSupport=true, so the pdbs would get deployed

  • And use --debug to start the debugger

  • Opening the url will show a Run tests button, which you can click after connecting with the IDE, to start running the tests

Notes, and TODO

  • WasmAppHost, along with the debug proxy are bundled in the WebAssembly.Sdk pack right now.

    • This might be changed in the future to use the dotnet app host pack pattern, and with
      additional support adding in the Sdk.
    • This would also allow using launchSettings.json, similar to blazor
  • WasmAppHost depends on host config in runtimeconfig.json, which can be
    controlled by a runtimeconfig.template.json in the project directory.

  • Needs more tests, cleanup, --help for command line arguments

  • app-support.*js in templates, and test-main.js need more work to share the code

Fixes #67236

@radical radical added NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) NO-REVIEW Experimental/testing PR, do NOT review it arch-wasm WebAssembly architecture labels Apr 29, 2022
@ghost ghost assigned radical Apr 29, 2022
@ghost
Copy link

ghost commented Apr 29, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: radical
Assignees: -
Labels:

NO-MERGE, NO-REVIEW, arch-wasm

Milestone: -

@radical
Copy link
Member Author

radical commented Apr 29, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical
Copy link
Member Author

radical commented Apr 29, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical
Copy link
Member Author

radical commented Apr 29, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical radical force-pushed the wasm-app-host branch 2 times, most recently from ff995f4 to cad622c Compare April 30, 2022 09:47
@radical
Copy link
Member Author

radical commented Apr 30, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical
Copy link
Member Author

radical commented May 1, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical radical force-pushed the wasm-app-host branch 2 times, most recently from d72a7c9 to 5f77c3e Compare May 3, 2022 17:54
@radical
Copy link
Member Author

radical commented May 3, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical
Copy link
Member Author

radical commented May 3, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical
Copy link
Member Author

radical commented May 3, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical
Copy link
Member Author

radical commented May 3, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical
Copy link
Member Author

radical commented May 17, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical radical marked this pull request as ready for review May 17, 2022 23:47
@radical radical requested a review from marek-safar as a code owner May 17, 2022 23:47
@radical radical requested review from pavelsavara, lewing and kg May 18, 2022 00:15
@radical
Copy link
Member Author

radical commented May 18, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical
Copy link
Member Author

radical commented May 18, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical
Copy link
Member Author

radical commented May 18, 2022

Runtime test failures #69517, and #69518 .

I will re-enable all the other jobs that I had disabled.

@radical
Copy link
Member Author

radical commented May 18, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@thaystg thaystg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It LGTM, and also I tested and it works :)

@radical
Copy link
Member Author

radical commented May 25, 2022

The failures are known, and have issues filed.

@radical radical merged commit 6b3ea40 into dotnet:main May 25, 2022
@radical radical deleted the wasm-app-host branch May 25, 2022 20:24
@ghost ghost locked as resolved and limited conversation to collaborators Jun 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Build-mono
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebAssembly Browser App project fails to run
3 participants